S1 = input().split()
S2 = input().split()

price = {}
ans = 0

for item in S1:
    temp = item.split(',') 
    price[temp[0]] = int(temp[1])
for item in S2:
    temp = item.split(',')
    ans = ans + price[temp[0]] * int(temp[1])
print(ans)